#include"udp_server.hpp"
using namespace std;
using namespace udp_server;


static void usage(string proc)
{
    cout<<"Usage:\n\t"<< proc <<" port\n"<<endl;
}
static vector<string>vs;
bool isPass(string command)
{
    bool pass=true;
    size_t pos = command.find("rm");
    if(pos != string::npos)pass=false;
    pos=command.find("rm");
    if(pos != string::npos)pass=false;
    pos=command.find("kill");
    if(pos != string::npos)pass=false;
    pos=command.find("while");
    if(pos != string::npos)pass=false;
    return pass;
    
    
    


}





string excuteComand(string command)
{
    //popen  
    //1.创建管道 2.创建子进程 3.通过FILE直接返回  4.返回值

    //1。检查指令是否安全

    if(!isPass(command))return "该指令不合法";


    FILE* fp =popen(command.c_str(),"r");
    if(fp==nullptr)return "None";

    //3.读取结果
    char line[1024];
    string result;
    while(fgets(line,sizeof(line),fp)!=NULL)
    {
        result+=line;
    }
    pclose(fp);

    return result;






}



//加密发送
string oper(string s)
{
    string ss;
    for(auto &e:s)
    {
        e+=1;
        ss.push_back(e);
    }

    return ss;
}



int main(int argc,char*argv[])
{
    if(argc!=2)
    {
        usage(argv[0]);
        exit(USING_ERR);
    }
    uint16_t port=atoi(argv[1]);



    // udp_server::UdpServer us;
    // unique_ptr<UdpServer> us(new UdpServer("120.78.126.148", 1111));
    // unique_ptr<UdpServer> us(new UdpServer(oper,port));
    unique_ptr<UdpServer> us(new UdpServer(port));

    us->InitServer_Start();


    // us->InitServer();
    // us->Start();

    
    


    

    return 0;
}